package com.yoomiito.app.widget.dialog;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.yoomiito.app.R;
import com.yoomiito.app.model.my.PayeeInfo;
import com.yoomiito.app.utils.ImageLoader;
import com.yoomiito.app.widget.CircleImageView;

public class UserInfoDialog extends BaseDialog implements View.OnClickListener {

    public OnTransferListener onTransferListener;
    private PayeeInfo mPayeeInfo;
    private TextView mTransferMoneyTv;
    private CircleImageView mUserHeadIv;
    private TextView mUserName;
    private TextView mUserAccount;

    public UserInfoDialog(@NonNull Context context) {
        this(context,0);
    }

    public UserInfoDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.dialog_2);
    }

    protected UserInfoDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    public View setView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_user_info,null,false);
        setWidthPercent(1);
        setmHeightPercent(0.65);
        setmGravity(Gravity.BOTTOM);
        view.findViewById(R.id.sure_transfer).setOnClickListener(this);
        mTransferMoneyTv = view.findViewById(R.id.transfer_money);
        mUserHeadIv = view.findViewById(R.id.user_head_iv);
        mUserName = view.findViewById(R.id.user_name);
        mUserAccount = view.findViewById(R.id.user_account);
        if (mPayeeInfo!=null){
//            mTransferMoneyTv.setText("转账金额 ¥"+mPayeeInfo.getMoney());
//            mUserName.setText(mPayeeInfo.getNickname());
//            mUserAccount.setText(mPayeeInfo.getMobile());
//            ImageLoader.getInstance().into(mContext,mPayeeInfo.getHeadimgurl(),mUserHeadIv);
            setUserInfo();
        }
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.sure_transfer:
                if (onTransferListener!=null){
                    onTransferListener.tranfer();
                    dismiss();
                }
                break;
        }
    }

    public interface OnTransferListener{
        void tranfer();
    }

    public void setOnTransferListener(OnTransferListener onTransferListener) {
        this.onTransferListener = onTransferListener;
    }

    public void setPayeeInfo(PayeeInfo payeeInfo) {
        mPayeeInfo = payeeInfo;
        if (mUserAccount!=null){
            setUserInfo();
        }
    }

    private void setUserInfo(){
        mTransferMoneyTv.setText("转账金额 ¥"+mPayeeInfo.getMoney());
        mUserName.setText(mPayeeInfo.getNickname());
        mUserAccount.setText(mPayeeInfo.getMobile());
        ImageLoader.getInstance().into(mContext,mPayeeInfo.getHeadimgurl(),mUserHeadIv);
    }
}
